package com;// -*- coding: utf-8 -*-

import com.DataStruct.Tree.TwoBinaryTree.TreeNode;
import com.Sort.Utils.SortUtils;
import org.junit.jupiter.api.Test;

import java.text.DecimalFormat;
import java.time.*;
import java.util.*;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.stream.IntStream;
import java.util.stream.Stream;


import static java.util.stream.Collectors.toList;

@SuppressWarnings("ALL")
/**
 * Project: SortTrain
 * Creator: yanking
 * Create time: 2021-11-22 15:29
 * IDE: IntelliJ IDEA
 * Introduction:
 */


public class test {

    SortUtils utils = new SortUtils();
    UnaryOperator<Integer> dda = x -> x + 1;

    public static void main(String[] args) {


        Scanner myScanner = new Scanner(System.in);
//        String name = myScanner.next();
//        if (checkPredicate(name, s -> s.length() > 5, b -> name.equals("Yang"))) {
//            System.out.println("Yes!");
//        }
//        while (myScanner.hasNextInt()) {
//            System.out.println(myScanner.nextInt());
//        }
        int[] nums = {1, 2, 3, 4, 5, 5, 6, 8, 9, 9, 888};

        Queue<Integer> queue = new PriorityQueue<>((a, b) -> b - a);
        for (int i = 0; i < nums.length; i++) {
            queue.offer(nums[i]);
        }
        while (!queue.isEmpty()) {
            System.out.println(queue.poll());
        }


//        int l = 0, r = nums.length - 1;
//        int cur = new Scanner(System.in).nextInt();
//        while (l < r) {
//            int mid = l + r + 1 >> 1;
//            if (mid >= cur) {
//                r = mid - 1;
//            } else {
//                l = mid;
//            }
//        }
//        System.out.print(l + "\t");
//        System.out.println(r);
//        System.out.println(nums[l] + "\t" + nums[r]);

//        ArrayList<Integer> heap = new ArrayList<>();
        //List<Integer> heap = Collections.synchronizedList(new ArrayList<>());
//        for (int i = 0; i < 10; i++) {
//            heap.add(i);
//        }
//
//        for (Integer integer : heap) {
//            System.out.print(integer + "\t\t");
//        }


    }

    @Test
    public static void test(List<Integer> heap) {
//        System.out.println(heap.get(2));
//        Map<Object, Object> objectObjectHashMap = new HashMap<>();
        PriorityQueue<Integer> integers = new PriorityQueue<>();

    }

    @Test
    public static boolean checkPredict(String name, Predicate<String> predicate) {
        return predicate.test(name);
    }

    public static boolean checkPredicate(String name, Predicate<String> pre1, Predicate<String> pre2) {
        return pre1.or(pre2).test(name);

    }

    public int lowbit(int x) {
        return x & (-x);
    }

    @Test
    public void shout133() {
        int k = 5;
        while (k > 0) {
            System.out.print(k + "\t");
            k -= lowbit(k);
        }
    }

    @Test
    public void shout00() {
//        String[] test = {"ac", "a", "bc", "dbc", "ebc", "fbc"};
//        Arrays.sort(test, Collections.reverseOrder());
//        Stream.of(test).forEach(a -> System.out.print(a + "\t"));
        TreeSet<Integer> set = new TreeSet<>();
        set.add(1);
        set.add(2);
        set.add(3);
        System.out.println(set.floor(3));
    }

    @Test
    public void shout03() {
        ArrayList<Integer> t = new ArrayList<>();
        t.add(null);
        t.add(null);
        for (int i = 0; i < t.size(); i++) {
            System.out.println(t.get(i));
        }

    }

    final static char[] digits = {
            '0', '1', '2', '3', '4', '5',
            '6', '7', '8', '9', 'a', 'b',
            'c', 'd', 'e', 'f', 'g', 'h',
            'i', 'j', 'k', 'l', 'm', 'n',
            'o', 'p', 'q', 'r', 's', 't',
            'u', 'v', 'w', 'x', 'y', 'z'
    };

    @Test

    public void shout1000() {
//        System.out.println(digits[14]);
        System.out.println(Integer.toBinaryString((int) Math.pow(2, 32)));
        System.out.println(Integer.bitCount((int) Math.pow(2, 32)));
//        System.out.println((long) (Math.pow(2, 32) + 1));
//        System.out.println((int) (Math.pow(2, 32) + 1));
//        System.out.println(Integer.toHexString(-1));
    }

    @SuppressWarnings("unchecked") // 抑制没有检测类型是否抑制的警告
    @Test
    public void shout04() {
//        List<Integer> test = new ArrayList() {{
//            add(5);
//            add(4);
//            add(3);
//            add(2);
//            add(1);
//        }};
        System.out.println(1 % 2);

    }

    @Test
    public void shout23() {
        System.out.println(Integer.toBinaryString(-1).length());
        System.out.println(Integer.toBinaryString(1 << 31).length());
    }

    @Test
    public void shout08() {
        // 随机数生成，去除1
        int a = 1;
        while (a == 1) {
            a = (int) (Math.random() * 4);
        }
        System.out.println(a);
    }


    @Test
    public void shout05() {
//        for (int i = 1; i <= 6; i++) {
//            System.out.println(((1 - i) + 6) % 6);
//        }
//        System.out.println(11 % 6);

        List<int[]> collect = IntStream.rangeClosed(1, 100).boxed().flatMap(a -> IntStream.rangeClosed(a, 100).filter(b -> Math.sqrt(a * a + b * b) % 1 == 0).mapToObj(b -> new int[]{a, b, (int) Math.sqrt(a * a + b * b)})).collect(toList());

        collect.forEach(a -> Arrays.stream(a).forEach(b -> System.out.print(b + "\t")));
    }

    @Test
    public void shout06() {
        int[] test = {22, 23, 20, 21, 45, 66, 7, 88};
        //System.out.println(new LargeNumT().largestNumber(test));
        int len = test.length;
        System.out.println(Arrays.stream(test).boxed().sorted(new sortNum()).collect(toList()));
    }

    public class sortNum implements Comparator<Integer> {

        @Override
        public int compare(Integer x, Integer y) {
            int sx = 10;
            int sy = 10;
            while (sx < x) {
                sx *= 10;
            }
            while (sy < y) {
                sy *= 10;
            }
            return (int) (-sy * x - y + x + y * sx);
        }

    }

    @Test
    public void shout07() {
        int[] test = {1, -1, 0, -2, 2};
        System.out.println(Arrays.stream(test).distinct().count());

    }

    @Test
    public void shout01() {
        ArrayList<Integer> test = new ArrayList<>();
        test.add(1);
        System.out.println(test.get(0));
    }

    @Test
    // 增强for循环无法初始化数组
    public void initial() {
        int[] B = {1, 2, 3};
        for (int i : B) {
            System.out.println(i);
            i = 0;
        }
        System.out.println("After initial!");
        for (int i : B) {
            System.out.println(i);
        }
    }

    @Test
    public void transData() {
        String data = "[[25,42],[7,14],[2,32],[25,28],[39,49],[1,50],[29,45],[18,47]]";
        dataChangeUpdate(data);
    }


    @Test
    public void shout5() {
//        System.out.println(1 + 5 + 5 >>> 1);
//        System.out.println(6 >>> 1);
        int num = -21;
        int i = 10;
        System.out.println((num % i + i) % i);

    }

    @Test
    public void shout55() {
        //System.out.println(IntStream.rangeClosed(0, 100).map(() ->  1, (c, b) -> c * b).boxed().collect(toList()));
//        System.out.println(14 ^ 2);
//        System.out.println(4 ^ 8);
        PriorityQueue<Integer> q = new PriorityQueue<>(2, (a, b) -> a - b);
        for (int i = 0; i < 10; i++) {
            q.offer(i);
        }
        for (int i = 0; i < 5; i++) {
            q.offer(6);
        }
        Iterator<Integer> iterator = q.iterator();
        while (iterator.hasNext()) {
            Integer next = iterator.next();
            System.out.print(next + "\t");
        }
        System.out.println("\n----------------------------");
        for (int i = 0; i < q.size(); i++) {
            System.out.print(q.poll() + "\t");
        }

    }

    public static int count = 1;

    @Test
    public void shout6() {
        System.out.println((int) Math.pow(2, 31));
        System.out.println(((int) Math.pow(2, 31) + "").length());

//        System.out.println(count);
//        count++;
//        shout6();

//        TreeSet<Integer> test = new TreeSet<Integer>();
//        test.add(1);
//        test.add(2);
//        System.out.println(test.floor(3));
//        char a = 'a';
//        char b = 'b';
//        char c = 'c';
//        System.out.println(String.valueOf(a) + b + c);
//        System.out.println((char) (a + 1));

    }

    @Test
    public void shout10() {
        // 测试队列是否可以加入null
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(null);
        queue.add(null);
        queue.add(null);
        if (!queue.isEmpty()) {
            System.out.println("NoNull!");
        } else {
            System.out.println("Null");
        }
        System.out.println(queue.size());
    }

    @Test
    public void dataChangeUpdate(String s) {
        String replace = s.replace('[', '{').replace(']', '}').replace('\n', ';');
        System.out.print("int[] test = " + replace);
    }

    @Test
    public void shout101() {
//        System.out.println(Integer.parseInt("-1"));


    }


    @Test
    public void shout15() {
        // Java int[] 比较
        int[] nums = {1, 2, 3, 4, 5};
        int n = nums.length;
        Integer[] ans = Arrays.stream(nums).boxed().sorted(Comparator.reverseOrder()).collect(toList()).toArray(new Integer[n]);
        for (Integer an : ans) {
            System.out.println(an);
        }
    }

    public String ta(String a) {
        assert a != null : "a is null";
        return "true";
    }


    @Test
    public void shout7() {
        DecimalFormat df = new DecimalFormat("00000000");
        //Integer.toBinaryString(df.format(1).)
        //System.out.println(new BigDecimal(Integer.toBinaryString(1)));
        // System.out.println(df.format(1));
        System.out.println(df.format(Integer.valueOf(Integer.toBinaryString(1))));
    }

    @Test
    public void shout17() {
        HashSet<Integer> test = new HashSet<Integer>() {{
            add(1);
            add(2);
            add(3);
        }};
        System.out.println(test.contains(1));
        test.remove(0);
    }

    public void deleteOtherElement(Set<Integer> set, Predicate<Integer> ifNCT) {
        set.removeIf(ifNCT);
    }

    @Test
    public int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    @Test
    public void shout3() {
        int n = 4, mask = 1 << 4;
        List<List<String>> ans = new ArrayList<>();
        for (int s = 0; s < mask; s++) {
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < n; i++) {
                if (((s >> 1) & 1) == 1) {
                    builder.append((s >> i & 1));
                }
            }
            List<String> list = new ArrayList<>();
            list.add(builder.toString());
            ans.add(list);
        }
        System.out.println(ans);
    }

    @Test
    public void shout4() {
        int n = 4;
        int[] nums = {5, 6, 7, 8};
        for (int i = 0; i < (1 << 4); i++) {
            System.out.println();
            for (int j = 0; j < n; j++) {
                if (((1 << j) & i) != 0) {
                    System.out.print(nums[j] + "\t");
                }
            }
        }

    }

    @Test
    public void shout02() {
        //To Test The continue label
        search:
        for (int j = 0; j < 6; j++) {
            System.out.println("now i == 3,It's time to go to the  bathroom");
            for (int i = 5; i > 0; i--) {
                System.out.println("I am in the loop");
                if (i == 3) {
                    continue search;
                }
            }
        }
    }


    @Test
    public void shout() {
        int i = 7;
        DecimalFormat df = new DecimalFormat("00000000");
        System.out.println(df.format(Integer.valueOf(Integer.toBinaryString(255))));
        System.out.println(255 >> 0);

    }

    @Test
    public void shout100() {
        System.out.println(3 - 3 % 2 - 1);
    }

    @Test
    public int bitCount_(int num) {
        int count = 0;
        while (num > 0) {
            if ((num & 1) == 1) {
                // 01023131 & 00000001
                ++count;
            }
            num >>= 1;
        }
        return count;
    }

    List<String> ans = new ArrayList();


    public void toAdd(StringBuilder builder) {
        ans.add(builder.append("Here").toString());
    }

    @Test
    public void shoutB() {
        HashSet<Integer> ans = new HashSet<>();
        ans.add(1);
        ans.add(2);
        ans.remove(ans.size());
        System.out.println(ans);
    }

    @Test
    public int bitCount2(int num) {
        int count = 0;
        while (num > 0) {
            num = num & (num - 1);
            count++;
        }
        return count;
    }

    @Test
    public int repeatBitCount(int i) {
        i = (i & 0x55555555) + ((i >>> 1) & 0x55555555);
        i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
        i = (i & 0x0f0f0f0f) + ((i >>> 4) & 0x0f0f0f0f);
        i = (i & 0x00ff00ff) + ((i >>> 8) & 0x00ff00ff);
        i = (i & 0x0000ffff) + ((i >>> 16) & 0x0000ffff);
        return i & 0x3f;
    }

    @Test
    public void say() {
//        List<Integer> res = new ArrayList<Integer>() {{
//            add(1);
//            add(2);
//            add(3);
//        }};
//        int index = 0;
//        res.remove(index);
//        System.out.print(res);
//        System.out.println(Integer.bitCount(2));


        //System.out.println(LocalDate.of(2022, Month.MARCH, 24));
//        System.out.println(Instant.now());
        ZoneId of = ZoneId.of("Europe/Rome");
        ZonedDateTime zone = Instant.now().atZone(of);
        System.out.println(zone);

    }

    @Test
    public void shout110() {

    }


}


